import threading,time

def run(n):
    semaphore.acquire()
    print('-'*30)
    print("\n Pid is: %s " % threading.get_ident()) #返回线程PID
    semaphore.release()

if __name__ == "__main__":

    semaphore = threading.BoundedSemaphore(2)
    threading.main_thread().setName('Chengd---python') #自定义主线程名称
    for i in range(3):
        thread_alive = threading.Thread(target=run,args=(i,))
        thread_alive.start()
    thread_alive.join()
    print('\n%s thread is done...'% threading.current_thread().getName())    #获取线程名
